package com.ijunfu.lambda._04_filter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @Title  : 集合过滤
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/18 13:54
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
public class Main {

    public static void main(String[] args) {
        List<String> fruits = Arrays.asList("banana", "apple", "pear", "grapefruit", "orange");

        List<String> arrs = new ArrayList<>();
        for(String fruit: fruits) {
            if(fruit.startsWith("p")) {
                arrs.add(fruit);
            }
        }

        arrs.stream().forEach(System.out::println);

        List<String> list = fruits.stream().filter(fruit -> fruit.startsWith("p")).collect(Collectors.toList());
        list.stream().forEach(System.out::println);
    }

}
